package com.nut.service.basearea;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.nut.dao.BaseAreaMapper;
import com.nut.pojo.BaseArea;
import com.nut.pojo.BaseAreaExample;

/**
*@author Nut
*@version 2018年8月14日 下午6:58:47
*@TODO
*
*/
@Service
public class AreaServiceImpl implements AreaServiceI {

	@Resource
	BaseAreaMapper areaMapper;
	@Override
	public List<BaseArea> getArea() {
		BaseAreaExample areaExample=new BaseAreaExample();
		areaExample.createCriteria().andParentidEqualTo(0);
		List<BaseArea> list=areaMapper.selectByExample(areaExample);
		for (BaseArea baseArea : list) {
			BaseAreaExample childExample=new BaseAreaExample();
			childExample.createCriteria().andParentidEqualTo(baseArea.getCodeid());
			List<BaseArea> children=areaMapper.selectByExample(childExample);
			for (BaseArea baseArea2 : children) {
				BaseAreaExample childExample2=new BaseAreaExample();
				childExample2.createCriteria().andParentidEqualTo(baseArea2.getCodeid());
				baseArea2.setChildren(areaMapper.selectByExample(childExample2));
			}
			baseArea.setChildren(children);
		}
		return list;
	}

}
